<html>
	<head>
		<script src="../../src/gears_init.js"></script>
		<script src="../../src/Norm.js"></script>
		<script src="../../src/Norm.Logger.Gears.js"></script>
		<script src="../../src/Norm.Database.Gears.js"></script>
		<script src="../../src/Norm.ResultIterator.Gears.js"></script>
		<script src="../../src/Norm.LastIdManager.js"></script>
		<script src="../../src/Norm.Events.js"></script>
		<script src="../../src/Norm.Sql.js"></script>
		<script src="../../src/Norm.Fields.js"></script>
		<script src="../../src/Norm.Model.js"></script>
		<script src="../../src/Norm.Introspection.js"></script>
		<script src="../../src/Norm.Transaction.js"></script>
		<script>
			Norm.Database.name = "test.events";
			var Person = new Norm.Model({
				name : "Person",
				fields : {
					firstName : new Norm.Fields.String({maxLength : 25}),
					lastName : new Norm.Fields.String({maxLength : 25})
				}
			});
			
			var Tests = {
				
				up : function() {
					Person.dropTable();
					Person.createTable();
				},
				
				"test if model events works" : function() {
					
					var flagSave = "";
					var flagRemove = "";
					Person.addListener("onBeforeSave", function() {
						flagSave += "Before";
					});
					Person.addListener("onAfterSave", function() {
						flagSave += "After";
					});
					Person.addListener("onBeforeRemove", function() {
						flagRemove += "Before";
					});
					Person.addListener("onAfterRemove", function() {
						flagRemove += "After";
					});
					var someone = new Person();
					someone.firstName = "John";
					someone.lastName = "Doe";
					someone.save();
					UnitTest.assertEqual("BeforeAfter", flagSave);
					someone.remove();
					UnitTest.assertEqual("BeforeAfter", flagRemove);
				},
				
				down : function() {
					Person.dropTable();
				}
			};
		</script>
		<script src="unit-test.js"></script>
	</head>
	<body>
		
	</body>
</html>
